<?php
	include_once("common.php");
	include_once("script/signup.php");

	if(sizeof($_POST) > 0){
		$result = signup($_POST['username'], $_POST['email']);
		if($result){
			# TODO: Send email
		}
	}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>COMP 353 Project</title>

    <!-- Bootstrap core CSS -->
    <link href="./css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="./css/template.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../../docs-assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
</head>
<body>
	<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
		<div class="container">
			<div class="navbar-header">
				<a class="brand" href="#">SEMS Lite</a>
			</div>
			<div class="navbar">
				<ul class="nav navbar-nav">
					<li><a href="index.php">Home</a></li>
					<li><a href="search.php">Search</a></li>
					<li class="active"><a href="signup.php">Signup</a></li>
				</ul>
<?php
	if(isVisitor()){
		echo '<form class="navbar-form pull-right" method="post" action="index.php">'."\n",
			'<input name="username" type="text" placeholder="Username" class="form-control">'."\n",
			'<input name="password" type="password" placeholder="Password" class="form-control">'."\n",
			'<button type="submit" class="btn">Sign in</button>'."\n",
			'</form>'."\n";
	}
	else{
		echo '<form class="navbar-form pull-right" method="post" action="index.php">'."\n",
			'<input type="submit" class="btn" name="logout" value="Logout">'."\n",
			'</form>'."\n";
	}
?>
			</div>
		</div>
	</div>
<!-- CONTENT -->
	<div class="container">
<?php
	if(isset($result)){
		if($result){
			echo '<div class="alert alert-success">',
				"Successful Sign up! Two emails have been sent to your email",
				'</div>';
		}
		else{
			# FIXME: It should be alert-error
			echo '<div class="alert alert-error">',
				"Invalid Sign up!",
				'</div>';
		}
	}
?>
		<form class="form-horizontal" action="signup.php" method="post">
			<legend>Sign up</legend>
			<div class="control-group">
				<label class="control-label" for="inputEmail">Email</label>
				<div class="controls">
					<input type="text" id="inputEmail" placeholder="Email" name="email">
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="inputUsername">Username</label>
				<div class="controls">
					<input type="text" id="inputUsername" placeholder="Username" name="username">
				</div>
			</div>
			<div class="control-group">
				<div class="controls">
					<button type="submit" class="btn btn-primary">Sign in</button>
				</div>
			</div>
		</form>
	</div>
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
	<!-- CDN -->
	<!-- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> -->
	<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
	<!-- LOCAL -->
    <script src="./js/jquery-1.10.2.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
  </body>
</html>
